package day2;

import java.util.Random;
import java.util.Scanner;

import org.junit.Test;

public class WhileTest {

	@Test
	public void test1() {
		//1、循环条件的初始化
		int i = 1;
		//2、循环条件的控制
		while (i <= 5) { 
			System.out.println("HelloWorld!!!");
			//3、循环条件的改变（趋向于条件的结束）
			i++;
		}
	}
	
	@Test
	public void test2() {
		for (int i = 1; i <= 5; i++) {
			System.out.println("HelloWorld");
		}
	}
	
	// 1+ 2+ 3+ 4+ ....+ 99+ 100=5050
	@Test
	public void test3() {
		int i = 1;
		int sum = 0;
		while (i <= 100) {
			System.out.println(i);
			sum = sum + i;
			i++;
		}
		System.out.println("sum:" + sum);
	}
	
	@Test
	public void test7() {
		int sum = 0;
		for (int i = 1; i <= 100; i++) {
			System.out.println(i);
			sum = sum + i;
		}
		System.out.println("sum:" + sum);
	}
	
	@Test
	public void test8() {
		Scanner scanner = new Scanner(System.in);
		// Random().nextInt(300)   		0~299
		// Random().nextInt(300)+1      1~300
		int random = new Random().nextInt(300) + 1;
		System.out.println(random);
		// for (;;) {}
		while (true) {
			System.out.println("猜吧！");
			int num = scanner.nextInt();
			if (num > random) {
				System.out.println("太大了");
			} else if (num < random) {
				System.out.println("太小了");
			} else {
				System.out.println("猜对了");
				// 退出while循环
				break;
			}
		}
	}
	
	@Test
	public void test88() {
		Scanner scanner = new Scanner(System.in);
		int password = 0;
		do {
			System.out.println("请输入密码：");
			password = scanner.nextInt();
		} while(password != 123);
	}
	
	@Test
	public void test9() {
		int count = 0;
		for (int i = 1; i <= 100; i++) {
			if (i % 7 == 0) {
				System.out.println(i);
				count++;
				System.out.println("count: " + count);
			}
		}
		System.out.println("count: " + count);
	}
	
	@Test
	public void test10() {
		// 1*9=9 2*9=18 .... 9*9=81
		for (int i = 1; i <= 9; i++) {
			// 2*9=18
			System.out.print(i + "*9=" + (i * 9) + "\t");
		}
	}
	
	@Test
	public void test11() {
		// ****
		for (int i = 1; i <= 4; i++) {
			System.out.print("*");
		}
		System.out.println();
		System.out.println("---------");
		//*
		//*
		//*
		for (int i = 1; i <= 3; i++) {
			System.out.println("*");
		}
		System.out.println("---------");
		for (int i = 1; i <= 3; i++) {// i=1,代表打印第一行
			for (int j = 1; j <= 4; j++) {
				System.out.print("*");
			}
			System.out.println();// 打印完一行之后换行
		}
	}
	
//	*
//	**
//	***
//	****
//	*****
	@Test
	public void test12() {
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}
		// i=1 j=1
		// i=2 j=2
		// ...
		// i=5 j=5
	}
	
	@Test
	public void test16() {
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= i; j++) {
				// 2*9=18  豆豆加加
				System.out.print(j + "*" + i + "=" + (i * j) + " \t");
			}
			System.out.println();
		}
	}
	
}
